local XMPQT = XLGetGlobal("XMPQT")

XMPQT.ASSERT = {}

function GetEditObject()
	local treeMananger = XLGetObject("Xunlei.UIEngine.TreeManager")
	local rootObjTree = treeMananger:GetUIObjectTree("XMPQT.MainObjTree.Instance")

	local bkgObject = rootObjTree:GetUIObject("app.bkg")
	local editObj = bkgObject:GetObject("mainwnd.body:RichEditPanel:edit_simple")
	
	return editObj
end


function XMPQT.ASSERT.Title(text)
	if text == nil or type(text) ~= "string" then
		return
	end
	
	AsynCall(function()
	local editObj = GetEditObject()
	local fmtold , bret = editObj:GetTextCharFormat()
	local fmt = {textcolor="#000000",weight = 6000,height = 18}
	editObj:SetTextCharFormat(fmt)
	editObj:AppendText(text.."\r\n")
	editObj:SetTextCharFormat(fmtold)
	end)

end
function Insert2Tree(text,state)
		local parent = nil
		local id = nil
		if XMPQT.TreeIdMap then 
			parent = XMPQT.tcIndex
			id = XMPQT.tcIndex*10000+XMPQT.TreeIdMap[XMPQT.tcIndex]
		end
		if XMPQT.TreeIdMap and parent and id then
			XMPQT.TreeIdMap[XMPQT.tcIndex] = XMPQT.TreeIdMap[XMPQT.tcIndex]+1
			XMPQT.Helper.InsertTreeItem(parent,id,text,state)
		end

end
function XMPQT.ASSERT.Info(text)
	if text == nil or type(text) ~= "string" then
		return
	end

	
	AsynCall(function()
		local editObj = GetEditObject()
		local fmtold , bret = editObj:GetTextCharFormat()
		local fmt = {textcolor="#000000"}
		editObj:SetTextCharFormat(fmt)
		editObj:AppendText(text.."\r\n")
		editObj:SetTextCharFormat(fmtold)
		Insert2Tree(text,0)
	
	end)

end

function XMPQT.ASSERT.Warning(text)
	if text == nil or type(text) ~= "string" then
		return
	end
	AsynCall(function()
		local editObj = GetEditObject()
		local fmtold , bret = editObj:GetTextCharFormat()
		local fmt = {textcolor="#00ffff"}
		editObj:SetTextCharFormat(fmt)
		editObj:AppendText(text.."\r\n")
		editObj:SetTextCharFormat(fmtold)
		
		Insert2Tree(text,13)
	end)
end

function XMPQT.ASSERT.Error(text)
		if text == nil or type(text) ~= "string" then
			return
		end
		AsynCall(function()
		local editObj = GetEditObject()
		local fmtold , bret = editObj:GetTextCharFormat()
		local fmt = {textcolor="#ff0000",weight = 6000,height = 16}
		editObj:SetTextCharFormat(fmt)
		editObj:AppendText(text.."\r\n")
		editObj:SetTextCharFormat(fmtold)
		
		Insert2Tree(text,12)
		
	end)
	
end

function XMPQT.ASSERT.Success(text)
	if text == nil or type(text) ~= "string" then
		return
	end
	AsynCall(function()
		local editObj = GetEditObject()
		local fmtold , bret = editObj:GetTextCharFormat()
		local fmt = {textcolor="#00ff00"}
		editObj:SetTextCharFormat(fmt)
		editObj:AppendText(text.."\r\n")
		editObj:SetTextCharFormat(fmtold)
	end)
end

